package com.briup.app01.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.app01.bean.Category;
import com.briup.app01.bean.CategoryExample;
import com.briup.app01.dao.CategoryMapper;
import com.briup.app01.service.ICategoryService;

@Service
public class CategoryServiceImpl implements ICategoryService {

	@Autowired
	private CategoryMapper categoryDao;

	@Override
	public List<Category> findAll() {

		return categoryDao.selectByExample(new CategoryExample());

	}

	@Override
	public Category findById(long id) {
		return categoryDao.selectByPrimaryKey(id);

	}

	@Override
	public void deleteById(long id) {
		categoryDao.deleteByPrimaryKey(id);
	}

	// 保存或者修改
	@Override
	public void saveOrUpdate(Category category) {
		if (category.getId() == null) {
			categoryDao.insert(category);
		} else {
			categoryDao.updateByPrimaryKey(category);
		}

	}

	// 模糊查询
	@Override
	public List<Category> findLikeName(String name) {
		CategoryExample example = new CategoryExample();
		example.createCriteria().andNameLike("%" + name + "%");
		return categoryDao.selectByExample(example);

	}

}
